package com.ymatou.iapi.sellercs.testcase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.sellercs.parameter.CsSessionDetail;
import com.ymatou.iapi.sellercs.parameter.MessageAttach;
import com.ymatou.iapi.sellercs.parameter.MessageAttachType;
import com.ymatou.iapi.sellercs.parameter.SellerSendMessageBean;
import com.ymatou.iapi.sellercs.parameter.SendMessageBean;
import com.ymatou.iapi.sellercs.parameter.SendMessageResp;
import com.ymatou.iapi.sellercs.parameter.SendMessageWithAttachBean;
import com.ymatou.iapi.sellercs.service.SendMessageWithAttachCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.model.YmtCssession;
import com.ymttest.database.model.YmtMessage;
import com.ymttest.database.model.YmtMessageAttach;
import com.ymttest.database.redis.ImRedisWapper;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

import redis.clients.jedis.Tuple;

/**
 * SendMessageWithAttach FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SendMessageWithAttach {
	private static SendMessageWithAttachBean sendmessagewithattachBean;
	private static SendMessageWithAttachCall sendmessagewithattachCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static String sellername = EnvSetup.getData("autotest_sellerName1");
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("SendMessageWithAttach");
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException {
		sendmessagewithattachBean = new SendMessageWithAttachBean();
		sendmessagewithattachCall = new SendMessageWithAttachCall();
		YmtSellerCSIMWapper = new YmtSellerCSIMWapper();
		SellerCSIMCallService.OffLine(sellerId, null);
		SellerCSIMCallService.OffLine(zsellerId, null);
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(sendmessagewithattachCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * @param SendMessageBean
	 * @param type
	 *            <br>
	 * 			0 ymt_queuesession <br>
	 * 			1 ymt_cssession 不在线的时候0 在线1 * @param unReadCount 期望的未读消息数量
	 * @throws InterruptedException
	 */
	private void verifyDB(SendMessageWithAttachBean SendMessageBean, Integer unReadCount) throws InterruptedException {
		YmtCssession info = YmtSellerCSIMWapper.selectYmtCssession(SendMessageBean.getMasterCSId(), SendMessageBean.getUserId()).get(0);
		Logger.debug("YmtQueuesession:" + FormatUtil.beanToGSONString(info));
		Logger.verifyNotNull(info.getBeginTime(), "验证BeginTime");
		Logger.verifyEquals(13, info.getFromPlatform(), "来源平台-固定13");
		Logger.verifyEquals(true, new Date().getTime() - info.getLastMessageTime().getTime() < 10000, "LastMessageTime-误差内");
		Logger.verifyEquals(SendMessageBean.getMasterCSId(), info.getMasterCSId(), "验证MasterCSId");
		Logger.verifyNotNull(info.getSessionNumber(), "验证SessionNumber");
		Logger.verifyEquals(unReadCount, info.getUnReadCount(), "unReadCount");
		// 0 User, 1 ReAssign, 2 CS
		Logger.verifyEquals(2, info.getOpenType(), "OpenType-2分配打开会话");
		Logger.verifyEquals(null, info.getCloseType(), "CloseType-没有关闭时未设置");
		Logger.verifyEquals(0, info.getStatus(), "Status-0开启");
		Logger.verifyEquals(0, info.getMark(), "Mark-0");
	}

	private void verifyReturn(SendMessageWithAttachBean sendmessageBean2, SendMessageResp result) {
		Logger.verifyEquals("200", sendmessagewithattachCall.getString("Status"), "验证Status");
		JUserWapper JUserWapper = new JUserWapper();
		String fromurl = JUserWapper.selectUserinfoexByUid(sendmessageBean2.getMasterCSId()).get(0).getLogoUrl();
		Logger.verifyEquals(fromurl == null ? JUserCallService.defaultSellerImg : fromurl, result.getFromUserLogo(), "验证FromUserLogo");
		String tourl = JUserWapper.selectUserinfoexByUid(sendmessageBean2.getUserId()).get(0).getLogoUrl();
		Logger.verifyEquals(tourl == null ? JUserCallService.defaultImg : tourl, result.getToUserLogo(), "验证ToUserLogo");

		String fromname = JUserWapper.selectUserinfoByUid(sendmessageBean2.getMasterCSId()).get(0).getLoginId();
		Logger.verifyEquals(fromname, result.getFromUserName(), "验证FromUserName");

		String toname = JUserWapper.selectUserinfoByUid(sendmessageBean2.getUserId()).get(0).getLoginId();
		Logger.verifyEquals(toname, result.getToUserName(), "验证toname");

		Logger.verifyEquals(0, result.getFromUserUnReadMessageCount(), "FromUserUnReadMessageCount");
		Logger.verifyEquals(0, result.getToUserUnReadMessageCount(), "ToUserUnReadMessageCount");
		Logger.verifyNotNull(result.getMessageId(), "验证msgId");
	}

	private YmtMessage verifyMessage(SendMessageWithAttachBean sendmessageBean2, String messageId) throws InterruptedException {
		ImDefaultWapper im=new ImDefaultWapper();
		YmtMessage msg =im.selectImInfo(sendmessagewithattachCall.getResult().getMessageId()).get(0);
		Logger.debug("msg:" + FormatUtil.beanToGSONString(msg));
		Logger.verifyEquals(sendmessageBean2.getMasterCSId(), msg.getMsgFromId(), "验证MsgFromId");
		Logger.verifyEquals(sendmessageBean2.getUserId(), msg.getMsgToId(), "验证MsgToId");
		Logger.verifyEquals(sendmessageBean2.getMessage(), msg.getMessage(), "验证Message");
		List<String> contentlist = sendmessageBean2.getMessageAttachList().stream().map(map->{return map.getContent();}).collect(Collectors.toList());
		List<Integer> typelist = sendmessageBean2.getMessageAttachList().stream().map(map->{return map.getType();}).collect(Collectors.toList());
		List<YmtMessageAttach> attach = im.selectMessageattachByMessageId(messageId);
		Logger.verifyEquals(sendmessageBean2.getMessageAttachList().size(), attach.size(), "验证附件数量");
		for (YmtMessageAttach ymtMessageAttach : attach) {
			Logger.verifyEquals(true,contentlist.contains(ymtMessageAttach.getContent()),"验证包含附件");
			Logger.verifyEquals(true,typelist.contains(ymtMessageAttach.getType()),"验证包含附件type");
		}
		return msg;
	}

	private void verifyRedis(SendMessageWithAttachBean SendMessageBean, Integer unReadCount) throws InterruptedException, ClientProtocolException, IOException {
		ImRedisWapper ImRedisWapper = new ImRedisWapper();
		Set<Tuple> set = ImRedisWapper.getCSession(SendMessageBean.getMasterCSId());
		set.forEach(t -> {
			Logger.debug("tuple:" + t.getScore() + ":" + t.getElement());
		});
		List<String> list = set.stream().map(t -> {
			return t.getElement();
		}).collect(Collectors.toList());
		Logger.verifyEquals(true, list.contains(SendMessageBean.getUserId().toString()), "验证QSession中包含有FromUserId");
		CsSessionDetail csSessionDetail = ImRedisWapper.getCSessionDetails(sellerId, SendMessageBean.getUserId(),sellerId);
		Logger.debug("CSessionDetails:" + FormatUtil.beanToGSONString(csSessionDetail));
		// TODO 这里没有主子账号考虑?
		Logger.verifyEquals(SendMessageBean.getCsId(), csSessionDetail.getCsId(), "验证csid");
		Logger.verifyEquals(JUserCallService.GetUserInfo(SendMessageBean.getCsId()).getLoginId(), csSessionDetail.getCsName(), "验证csname");
		Logger.verifyNotNull(csSessionDetail.getSessionId(), "验证SessionId不为空");
		Logger.verifyNotNull(csSessionDetail.getSessionNumber(), "验证SessionNumber不为空");

	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SendMessageWithAttach_001() {
		Logger.start(true, "进行中会话发送附件消息成功");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			// APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			// 触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);

			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			List<MessageAttach> MessageAttachList = new ArrayList<MessageAttach>();
			MessageAttach ma = new MessageAttach();
			ma.setContent("提示");
			ma.setType(2);
			MessageAttachList.add(ma);
			sendmessagewithattachBean.setMessageAttachList(MessageAttachList);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			verifyReturn(sendmessagewithattachBean, sendmessagewithattachCall.getResult());
			verifyMessage(sendmessagewithattachBean, sendmessagewithattachCall.getResult().getMessageId());
			verifyDB(sendmessagewithattachBean, 0);
			verifyRedis(sendmessagewithattachBean, 0);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_SendMessageWithAttach_002() {
		Logger.start(true, "不输入MasterCSId失败");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			sendmessagewithattachBean.setCsId(sellerId);
//			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			Logger.verifyEquals("500", sendmessagewithattachCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_SendMessageWithAttach_003() {
		Logger.start(true, "不输入CsId失败");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
//			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			Logger.verifyEquals("500", sendmessagewithattachCall.getString("Status"), "验证Status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_SendMessageWithAttach_004() {
		Logger.start(true, "不输入UserId失败");
		try {
			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
//			sendmessagewithattachBean.setUserId(userId);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			Logger.verifyEquals("400", sendmessagewithattachCall.getString("Status"), "验证Status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_SendMessageWithAttach_005() {
		Logger.start(true, "不输入Message失败");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
//			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
//			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			Logger.verifyEquals("400", sendmessagewithattachCall.getString("Status"), "验证Status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SendMessageWithAttach_006() {
		Logger.start(true, "没有附件发送消息成功");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			// APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			// 触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);

			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			List<MessageAttach> MessageAttachList = new ArrayList<MessageAttach>();
//			MessageAttach ma = new MessageAttach();
//			ma.setContent("提示");
//			ma.setType(2);
//			MessageAttachList.add(ma);
			sendmessagewithattachBean.setMessageAttachList(MessageAttachList);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			verifyReturn(sendmessagewithattachBean, sendmessagewithattachCall.getResult());
			verifyMessage(sendmessagewithattachBean, sendmessagewithattachCall.getResult().getMessageId());
			verifyDB(sendmessagewithattachBean, 0);
			verifyRedis(sendmessagewithattachBean, 0);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SendMessageWithAttach_007() {
		Logger.start(true, "发送多个附件成功");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			// APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			// 触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);

			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			List<MessageAttach> MessageAttachList = new ArrayList<MessageAttach>();
			MessageAttach ma = new MessageAttach();
			ma.setContent("{" + " \"MinPrice\" : 6," + " \"TariffType\" : 0," + " \"ProductDesc\" : \"新发布测试商品_zjf\"," + " \"ProductId\" : \"1b2c7efb-77e7-46c3-ab51-05b51c9ae837\","
					+ " \"ProductPics\" : [" + "  \"http:\\/\\/pic1.ymatou.com\\/G01\\/\\/M00\\/3A\\/B5\\/rBBlD1n4KfWAdwsUAAd-Uj1GHqM097.png\"" + " ]," + " \"DeliveryType\" : 3,"
					+ " \"IsPreSale\" : false," + " \"MaxPrice\" : 6," + " \"FreeShipping\" : true," + " \"Price\" : 12," + " \"IsPSPProduct\" : false," + " \"IsNew\" : false"
					+ "}");
			ma.setType(5);
			MessageAttachList.add(ma);
			
			MessageAttach ma2 = new MessageAttach();
			ma2.setContent("提示2");
			ma2.setType(2);
			MessageAttachList.add(ma2);
			
			sendmessagewithattachBean.setMessageAttachList(MessageAttachList);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			verifyReturn(sendmessagewithattachBean, sendmessagewithattachCall.getResult());
			verifyMessage(sendmessagewithattachBean, sendmessagewithattachCall.getResult().getMessageId());
			verifyDB(sendmessagewithattachBean, 0);
			verifyRedis(sendmessagewithattachBean, 0);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SendMessageWithAttach_008() {
		Logger.start(true, "没有进行中的会话发送附件消息成功,创建新会话");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			// APP上线
			SellerCSIMCallService.AppLogin(sellerId);
//			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
//			SellerCSIMCallService.SendMessage(sendmessageBean);
			// 触发分配
//			SellerCSIMCallService.Assign();
//			Thread.sleep(5000);

			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			List<MessageAttach> MessageAttachList = new ArrayList<MessageAttach>();
			MessageAttach ma = new MessageAttach();
			ma.setContent("提示");
			ma.setType(2);
			MessageAttachList.add(ma);
			sendmessagewithattachBean.setMessageAttachList(MessageAttachList);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			verifyReturn(sendmessagewithattachBean, sendmessagewithattachCall.getResult());
			verifyMessage(sendmessagewithattachBean, sendmessagewithattachCall.getResult().getMessageId());
			verifyDB(sendmessagewithattachBean, 0);
			verifyRedis(sendmessagewithattachBean, 0);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SendMessageWithAttach_009() {
		Logger.start(true, "进行中会话发送附件消息成功,发送商品卡片");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			// APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			// 触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);

			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			List<MessageAttach> MessageAttachList = new ArrayList<MessageAttach>();
			MessageAttach ma = new MessageAttach();
			ma.setContent("{" + " \"MinPrice\" : 6," + " \"TariffType\" : 0," + " \"ProductDesc\" : \"新发布测试商品_zjf\"," + " \"ProductId\" : \"1b2c7efb-77e7-46c3-ab51-05b51c9ae837\","
					+ " \"ProductPics\" : [" + "  \"http:\\/\\/pic1.ymatou.com\\/G01\\/\\/M00\\/3A\\/B5\\/rBBlD1n4KfWAdwsUAAd-Uj1GHqM097.png\"" + " ]," + " \"DeliveryType\" : 3,"
					+ " \"IsPreSale\" : false," + " \"MaxPrice\" : 6," + " \"FreeShipping\" : true," + " \"Price\" : 12," + " \"IsPSPProduct\" : false," + " \"IsNew\" : false"
					+ "}");
			ma.setType(5);
			MessageAttachList.add(ma);
			sendmessagewithattachBean.setMessageAttachList(MessageAttachList);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			verifyReturn(sendmessagewithattachBean, sendmessagewithattachCall.getResult());
			verifyMessage(sendmessagewithattachBean, sendmessagewithattachCall.getResult().getMessageId());
			verifyDB(sendmessagewithattachBean, 0);
			verifyRedis(sendmessagewithattachBean, 0);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SendMessageWithAttach_010() {
		Logger.start(true, "客服离线发送消息失败");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);

			sendmessagewithattachBean.setCsId(sellerId);
			sendmessagewithattachBean.setMasterCSId(sellerId);
			sendmessagewithattachBean.setMessage("MessageAttach:" + YMTDateUtil.getBeforeOrNextDay(0));
			sendmessagewithattachBean.setUserId(userId);
			List<MessageAttach> MessageAttachList = new ArrayList<MessageAttach>();
			MessageAttach ma = new MessageAttach();
			ma.setContent("提示");
			ma.setType(2);
			MessageAttachList.add(ma);
			sendmessagewithattachBean.setMessageAttachList(MessageAttachList);
			sendmessagewithattachCall.setData(sendmessagewithattachBean);
			sendmessagewithattachCall.callService();
			Logger.verifyEquals("500", sendmessagewithattachCall.getString("Status"), "验证Status");
//子客服不在线，发起会话失败
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 获取实际值
	 * @param invalue
	 * @return
	 */
//	private Integer getAttachTypeOrdinal(Integer invalue){
//		return MessageAttachType.valueOf(invalue).ordinal();
//	}
}